import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

export const Layout = () => import("@/layouts/index.vue");


// 动态路由
import resultRoutes from "./modules/result.ts";

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
	{
		path: "/",
		component: Layout,
		redirect: "/index",
		children: [
			{
				path: "/index",
				component: () => import('@/views/home/index.vue'),
				name: "Index",
				meta: { title: "首页", icon: "home", affix: true },
			},
			
		],
	},
	...resultRoutes,
];
/**
 * 创建路由
 */
const router = createRouter({
	history: createWebHashHistory('/'),
	routes: constantRoutes as RouteRecordRaw[],
	// 刷新时，滚动条位置还原
	scrollBehavior(to, from, savedPosition) {
		if (savedPosition) {
			return savedPosition
		}
		if (to.hash) {
			return {
				el: to.hash,
				behavior: 'smooth'
			}
		} else {
			return {
				top: 0,
				behavior: 'smooth'
			}
		}
	}
});
/**
 * 重置路由
 */
export function resetRouter() {
	// 重置路由到登录页面
	router.replace({ path: "/login" });
}

export default router;



